<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是npm包发布与管理的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV01-Hexo-02-npm包的发布与管理">
<meta property="og:url" content="https://sumumm.github.io/post/5d78b485.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是npm包发布与管理的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV01-Hexo-02-npm%E5%8C%85%E7%9A%84%E5%8F%91%E5%B8%83%E4%B8%8E%E7%AE%A1%E7%90%86/img/004NPM01.png">
<meta property="article:published_time" content="2023-07-02T08:16:51.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.072Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="博客搭建">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV01-Hexo-02-npm%E5%8C%85%E7%9A%84%E5%8F%91%E5%B8%83%E4%B8%8E%E7%AE%A1%E7%90%86/img/004NPM01.png">


<link rel="canonical" href="https://sumumm.github.io/post/5d78b485.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/5d78b485.html","path":"post/5d78b485.html","title":"LV01-Hexo-02-npm包的发布与管理"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV01-Hexo-02-npm包的发布与管理 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81npm%E7%AE%80%E4%BB%8B"><span class="nav-text">一、npm简介</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%BB%80%E4%B9%88%E6%98%AFnpm%EF%BC%9F"><span class="nav-text">1. 什么是npm？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%9C%89%E4%BB%80%E4%B9%88%E7%94%A8%EF%BC%9F"><span class="nav-text">2. 有什么用？</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81npm%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8"><span class="nav-text">二、npm的基本使用</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E6%B3%A8%E5%86%8C%E8%B4%A6%E5%8F%B7"><span class="nav-text">1. 注册账号</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-npm%E5%AE%89%E8%A3%85%E4%B8%8E%E6%9B%B4%E6%96%B0"><span class="nav-text">2. npm安装与更新</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-npm%E7%AE%A1%E7%90%86%E6%8F%92%E4%BB%B6"><span class="nav-text">3. npm管理插件</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E5%AE%89%E8%A3%85%E6%8F%92%E4%BB%B6"><span class="nav-text">3.1 安装插件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E5%8D%B8%E8%BD%BD%E6%8F%92%E4%BB%B6"><span class="nav-text">3.2 卸载插件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-%E6%9B%B4%E6%96%B0%E6%8F%92%E4%BB%B6"><span class="nav-text">3.3 更新插件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-npm%E9%A1%B9%E7%9B%AE%E5%88%9D%E5%A7%8B%E5%8C%96"><span class="nav-text">4. npm项目初始化</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-%E5%88%9B%E5%BB%BA%E6%96%87%E4%BB%B6%E5%A4%B9"><span class="nav-text">4.1 创建文件夹</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-%E5%88%9D%E5%A7%8B%E5%8C%96%E6%96%87%E4%BB%B6%E5%A4%B9"><span class="nav-text">4.2 初始化文件夹</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-3-package-json%E5%8F%82%E6%95%B0%E8%A7%A3%E8%AF%BB"><span class="nav-text">4.3 package.json参数解读</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-npm%E9%A1%B9%E7%9B%AE%E5%8F%91%E5%B8%83%E4%B8%8E%E7%AE%A1%E7%90%86"><span class="nav-text">5.npm项目发布与管理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#5-1-%E6%A3%80%E6%9F%A5npm%E6%BA%90"><span class="nav-text">5.1 检查npm源</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-2-%E6%9C%AC%E5%9C%B0%E7%99%BB%E5%BD%95npm"><span class="nav-text">5.2 本地登录npm</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-3-%E5%8F%91%E5%B8%83%E9%A1%B9%E7%9B%AE"><span class="nav-text">5.3 发布项目</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-4-%E6%9B%B4%E6%96%B0%E6%9C%AC%E5%9C%B0%E9%A1%B9%E7%9B%AE%E7%89%88%E6%9C%AC%E5%B9%B6%E5%8F%91%E5%B8%83"><span class="nav-text">5.4 更新本地项目版本并发布</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-5-%E6%92%A4%E9%94%80%E7%89%88%E6%9C%AC%E7%9A%84%E5%8F%91%E5%B8%83"><span class="nav-text">5.5 撤销版本的发布</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-6-%E6%9F%A5%E7%9C%8B%E7%89%88%E6%9C%AC%E4%BF%A1%E6%81%AF"><span class="nav-text">5.6 查看版本信息</span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/5d78b485.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV01-Hexo-02-npm包的发布与管理 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV01-Hexo-02-npm包的发布与管理
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-07-02 16:16:51" itemprop="dateCreated datePublished" datetime="2023-07-02T16:16:51+08:00">2023-07-02</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" itemprop="url" rel="index"><span itemprop="name">博客搭建</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>3.5k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>13 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是npm包发布与管理的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV01-Hexo-02-npm%E5%8C%85%E7%9A%84%E5%8F%91%E5%B8%83%E4%B8%8E%E7%AE%A1%E7%90%86/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr><td align="center">参考方向  </td><td align="center">参考原文</td></tr>    <tr><td align="left">---</td><td align="left"><a href="" target="_blank">--- <i class="fa fa-external-link-alt"></i> </a></td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">---</td>        <td align="left">--- <a href="" target="_blank">  <i class="fa fa-external-link-alt"></i></a></td>      </tr></table>
              </div>
            </details>

<p>在使用<code>Hexo</code>的过程中，会需要优化主题的显示，来达到自己想要的一个效果，<code>Hexo</code>有强大的插件系统，开发者能轻松扩展功能而不用修改核心模块的源码。在<code>Hexo</code>中有两种形式的插件：脚本（Scripts）和插件（Packages），我可能更倾向于使用插件，这种方式对源码的改动方式应该是最小的了，而本文主要就是先介绍最基础的<code>npm</code>包的发布和管理。</p>
<h1 id="一、npm简介"><a href="#一、npm简介" class="headerlink" title="一、npm简介"></a><font size=3>一、<code>npm</code>简介</font></h1><h2 id="1-什么是npm？"><a href="#1-什么是npm？" class="headerlink" title="1. 什么是npm？"></a><font size=3>1. 什么是npm？</font></h2><p><code>npm is the world&#39;s largest software registry. Open source developers from every continent use npm to share and borrow packages, and many organizations use npm to manage private development as well.</code></p>
<p>官网是这样介绍<code>npm</code>的，翻译过来就是，<code>npm</code>是世界上最大的软件注册中心。来自各个大洲的开源开发者都使用<code>npm</code>来共享和借用包，许多组织也使用<code>npm</code>来管理私人开发。简单来说，<code>npm</code>就是<code>javascript</code>的包管理工具，类似<code>python</code>的<code>pip</code>。<code>npm</code>是和<code>Node.js</code>一起发布的，只要安装了<code>Node.js</code>，<code>npm</code>也默认会被安装。</p>
<h2 id="2-有什么用？"><a href="#2-有什么用？" class="headerlink" title="2. 有什么用？"></a><font size=3>2. 有什么用？</font></h2><p>那么<code>npm</code>可以用用来干什么呢？</p>
<div class="note default"><ul>
<li>为你的应用调整代码包，或者合并它们。</li>
<li>下载可以立即使用的独立工具。</li>
<li>运行包而不使用<a href="https://www.npmjs.com/package/npx" target="_blank"><code>npx</code></a>下载。</li>
<li>与任何地方的任何<code>npm</code>用户共享代码。</li>
<li>将代码限制给特定的开发人员。</li>
<li>创建组织来协调包维护、编码和开发人员。</li>
<li>使用组织形式组建虚拟团队。</li>
<li>管理多个版本的代码和代码依赖关系。</li>
<li>当底层代码更新时，可以轻松地更新应用程序。</li>
<li>发现解决同一难题的多种方法。</li>
<li>找到其他正在处理类似问题和项目的开发人员。</li>
</ul>
</div>

<details class="note info no-icon"><summary><p>点击查看相关文档</p>
</summary>
<p>相关文档：</p>
<table>
    <tr>
        <td align="left">
        npm主页
        </td>
        <td align="left">
        <a href="https://www.npmjs.com/" target="_blank">https://www.npmjs.com/</a>
        </td>
    </tr>
    <tr>
        <td align="left">
        npm说明文档(英文)
        </td>
        <td align="left">
        <a href="https://docs.npmjs.com/" target="_blank">https://docs.npmjs.com/</a>
        </td>
    </tr>
    <tr>
        <td align="left">
        npm说明文档(中文)
        </td>
        <td align="left">
        <a href="https://www.npmjs.cn/" target="_blank">https://www.npmjs.cn/</a>
        </td>
    </tr>
    <tr>
        <td align="left">
        node主页
        </td>
        <td align="left">
        <a href="https://nodejs.dev/" target="_blank">https://nodejs.dev/</a>
        </td>
    </tr>
    <tr>
        <td align="left">
        node说明文档(英文)
        </td>
        <td align="left">
        <a href="https://nodejs.dev/learn" target="_blank">https://nodejs.dev/learn</a>
        </td>
    </tr>
    <tr>
        <td align="left">
        node说明文档（中文）
        </td>
        <td align="left">
        <a href="http://nodejs.cn/learn" target="_blank">http://nodejs.cn/learn</a>
        </td>
    </tr>
</table>

</details>

<h1 id="二、npm的基本使用"><a href="#二、npm的基本使用" class="headerlink" title="二、npm的基本使用"></a><font size=3>二、<code>npm</code>的基本使用</font></h1><h2 id="1-注册账号"><a href="#1-注册账号" class="headerlink" title="1. 注册账号"></a><font size=3>1. 注册账号</font></h2><p>这个没什么可写的，进入官网，点击<code>Sign Up</code>按照提示进行注册即可，注册还是很简单的，注册完毕之后要记得会提示验证邮箱，这个时候注意验证就好了，不验证的话可能会有问题。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV01-Hexo-02-npm%E5%8C%85%E7%9A%84%E5%8F%91%E5%B8%83%E4%B8%8E%E7%AE%A1%E7%90%86/img/004NPM01.png" style="zoom: 33%;" >


<h2 id="2-npm安装与更新"><a href="#2-npm安装与更新" class="headerlink" title="2. npm安装与更新"></a><font size=3>2. <code>npm</code>安装与更新</font></h2><p>上边已经有所提及，<code>npm</code>和<code>Node.js</code>是一起发布的，只要安装了<code>Node.js</code>，<code>npm</code>也是自动安装了的。</p>
<ul>
<li>查看<code>npm</code>和<code>Node.js</code>版本</li>
</ul>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">node -v  # 查看node版本</span><br><span class="line">npm -v   # 查看npm版本</span><br></pre></td></tr></table></figure>

<ul>
<li>更新<code>npm</code>版本</li>
</ul>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install npm@latest -g</span><br></pre></td></tr></table></figure>

<h2 id="3-npm管理插件"><a href="#3-npm管理插件" class="headerlink" title="3. npm管理插件"></a><font size=3>3. <code>npm</code>管理插件</font></h2><h3 id="3-1-安装插件"><a href="#3-1-安装插件" class="headerlink" title="3.1 安装插件"></a><font size=3>3.1 安装插件</font></h3><figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">npm install packageName            # 本地安装，安装到项目目录下，不在package.json中写入依赖</span><br><span class="line">npm install packageName -g         # 全局安装，安装在Node安装目录下的node_modules下</span><br><span class="line">npm install packageName --save     # 安装到项目目录下，并在package.json文件的dependencies中写入依赖，简写为-S</span><br><span class="line">npm install packageName --save-dev # 安装到项目目录下，并在package.json文件的devDependencies中写入依赖，简写为-D</span><br><span class="line">npm install packageName@version --save # 安装指定版本</span><br></pre></td></tr></table></figure>

<p>可以通过以上命令来对插件进行安装，还有一种就是自己按照相应的语法写一个<code>package.json</code>文件，然后在该文件所在目录执行<code>npm install</code>即可安装<code>package.json</code>文件中的所有插件。</p>
<p>我一般还是只在<code>Hexo</code>中使用该命令，所以<code>npm install packageName --save</code>命令使用的较多，另外就是<code>npm 5</code>之后版本默认会修改<code>package.json</code>，不再需要<code>--save</code>参数，也就是说，就算现在去掉该参数，再通过<code>npm install</code>命令依然可以安装相应插件。更多内容可以这里：<a href="https://docs.npmjs.com/cli/v7/commands/npm-install" target="_blank"><code>npm-install</code><i class="fa fa-external-link-alt"></i></a></p>
<h3 id="3-2-卸载插件"><a href="#3-2-卸载插件" class="headerlink" title="3.2 卸载插件"></a><font size=3>3.2 卸载插件</font></h3><figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm uninstall packageName      # 删除packageName模块</span><br><span class="line">npm uninstall -g packageName   # 删除全局模块packageName</span><br></pre></td></tr></table></figure>

<h3 id="3-3-更新插件"><a href="#3-3-更新插件" class="headerlink" title="3.3 更新插件"></a><font size=3>3.3 更新插件</font></h3><figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">更新一个或多个模块，加上-g参数，表示更新全局的模块</span></span><br><span class="line">npm update packageName</span><br><span class="line">npm update packageName -g</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">更新时同时修改package.json文件,不要--save也没有问题</span></span><br><span class="line">npm update packageName --save-dev  # 在package.json文件的devDependencies中写入依赖</span><br><span class="line">npm update packageName --save</span><br></pre></td></tr></table></figure>

<h2 id="4-npm项目初始化"><a href="#4-npm项目初始化" class="headerlink" title="4. npm项目初始化"></a><font size=3>4. <code>npm</code>项目初始化</font></h2><p>由于我是针对<code>hexo</code>插件来使用<code>npm</code>，所以文件夹命名按照<code>hexo</code>的插件要求命名，<code>hexo</code>要求插件文件夹名称开头必须为 <code>hexo-</code>，如此一来<code> hexo</code>才会在启动时载入否则 <code>hexo</code>将会忽略它。</p>
<h3 id="4-1-创建文件夹"><a href="#4-1-创建文件夹" class="headerlink" title="4.1 创建文件夹"></a><font size=3>4.1 创建文件夹</font></h3><figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">进入自己相应的文件夹，并创建npm项目文件夹</span></span><br><span class="line">mkdir hexo-npm-test</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">进入创建的文件夹</span></span><br><span class="line">cd hexo-npm-test</span><br></pre></td></tr></table></figure>

<h3 id="4-2-初始化文件夹"><a href="#4-2-初始化文件夹" class="headerlink" title="4.2 初始化文件夹"></a><font size=3>4.2 初始化文件夹</font></h3><figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm init</span><br></pre></td></tr></table></figure>

<p>使用该命令初始化时，会打开项目初始化向导，在命令行窗口会提示让自己输入各个参数，所有显示信息如下所示：</p>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">npm init</span></span><br><span class="line">This utility will walk you through creating a package.json file.</span><br><span class="line">It only covers the most common items, and tries to guess sensible defaults.</span><br><span class="line"></span><br><span class="line">See `npm help init` for definitive documentation on these fields</span><br><span class="line">and exactly what they do.</span><br><span class="line"></span><br><span class="line">Use `npm install &lt;pkg&gt;` afterwards to install a package and</span><br><span class="line">save it as a dependency in the package.json file.</span><br><span class="line"></span><br><span class="line">Press ^C at any time to quit.</span><br><span class="line">package name: (hexo-npm-test)</span><br><span class="line">version: (1.0.0)</span><br><span class="line">description:</span><br><span class="line">entry point: (index.js)</span><br><span class="line">test command:</span><br><span class="line">git repository:</span><br><span class="line">keywords:</span><br><span class="line">author:</span><br><span class="line">license: (ISC)</span><br><span class="line">About to write to E:\MyStudy\VScode\hexofiles\hexo-npm-test\package.json:</span><br><span class="line"></span><br><span class="line">&#123;</span><br><span class="line">  &quot;name&quot;: &quot;hexo-npm-test&quot;,</span><br><span class="line">  &quot;version&quot;: &quot;1.0.0&quot;,</span><br><span class="line">  &quot;description&quot;: &quot;&quot;,</span><br><span class="line">  &quot;main&quot;: &quot;index.js&quot;,</span><br><span class="line">  &quot;scripts&quot;: &#123;</span><br><span class="line">    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;author&quot;: &quot;&quot;,</span><br><span class="line">  &quot;license&quot;: &quot;ISC&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">Is this OK? (yes) yes</span><br></pre></td></tr></table></figure>

<p>该命令有一个参数<code>--yes</code>，若使用以下命令，则创建默认<code>package.json</code>文件，不需要自己在命令行输入，后续直接修改该文件即可。</p>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm init --yes</span><br></pre></td></tr></table></figure>

<p>创建的文件信息如下，内容与不带参数创建的一致，看个人喜好选择要不要带参数吧。</p>
<figure class="highlight json"><figcaption><span>json</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;name&quot;</span><span class="punctuation">:</span> <span class="string">&quot;hexo-npm-test&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;version&quot;</span><span class="punctuation">:</span> <span class="string">&quot;1.0.0&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;description&quot;</span><span class="punctuation">:</span> <span class="string">&quot;&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;main&quot;</span><span class="punctuation">:</span> <span class="string">&quot;index.js&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;scripts&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">    <span class="attr">&quot;test&quot;</span><span class="punctuation">:</span> <span class="string">&quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;</span></span><br><span class="line">  <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;keywords&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="punctuation">]</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;author&quot;</span><span class="punctuation">:</span> <span class="string">&quot;&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;license&quot;</span><span class="punctuation">:</span> <span class="string">&quot;ISC&quot;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>

<h3 id="4-3-package-json参数解读"><a href="#4-3-package-json参数解读" class="headerlink" title="4.3 package.json参数解读"></a><font size=3>4.3 <code>package.json</code>参数解读</font></h3><details class="note info no-icon"><summary><p>点击查看参考文档</p>
</summary>
<table>
    <tr>
        <td align="center">
            参考文档
        </td>
        <td align="center">
            名称链接
        </td>
    </tr>
    <tr>
        <td align="center">
            阮一峰
        </td>
        <td align="left">
            <a href="https://javascript.ruanyifeng.com/nodejs/packagejson.html" target="_blank">《JavaScript 标准参考教程（alpha）》——package.json文件<a>
        </td>
    </tr>
    <tr>
        <td align="center">
            官方文档
        </td>
        <td align="left">
            <a href="https://docs.npmjs.com/cli/v7/configuring-npm/package-json" target="_blank">《npm Docs
》——package.json<a>
        </td>
    </tr>
</table>

</details>

<table>
    <tr>
        <td align="center">
            参数
        </td>
        <td align="center">
            说明
        </td>
    </tr>
    <tr>
        <td align="center">
            name
        </td>
        <td align="left">
            项目的名称。
        </td>
    </tr>
    <tr>
        <td align="center">
            version
        </td>
        <td align="left">
            项目的版本，默认是从V1.0.0开始，可以自己修改，遵守“大版本.次要版本.小版本”的格式。
        </td>
    </tr>
    <tr>
        <td align="center">
            scripts
        </td>
        <td align="left">
            指定了运行脚本命令的npm命令行缩写；<br>
            例如："test": "tap test/*.js" 就表示执行npm run test的时候所要执行的命令为 tap test/*.js 。
        </td>
    </tr>
    <tr>
        <td align="center">
            bin
        </td>
        <td align="left">
            指定各个内部命令对应的可执行文件的位置。<br>
        </td>
    </tr>
    <tr>
        <td align="center">
            main
        </td>
        <td align="left">
            指定加载的入口文件，require('moduleName')就会加载这个文件。这个字段的默认值是模块根目录下面的index.js。
        </td>
    </tr>
    <tr>
        <td align="center">
            author
        </td>
        <td align="left">
            项目的作者。
        </td>
    </tr>
    <tr>
        <td align="center">
            repository
        </td>
        <td align="left">
            项目代码存放地方类型，如：git或svn。
        </td>
    </tr>
    <tr>
        <td align="center">
            keywords
        </td>
        <td align="left">
            项目关键字。
        </td>
    </tr>
    <tr>
        <td align="center">
            description
        </td>
        <td align="left">
            项目简介，字符串，方便在npm search中搜索。
        </td>
    </tr>
    <tr>
        <td align="center">
            license
        </td>
        <td align="left">
            许可证。
        </td>
    </tr>
    <tr>
        <td align="center">
            dependencies
        </td>
        <td align="left" rowspan="2">
            dependencies字段指定了项目运行所依赖的模块;devDependencies指定项目开发所需要的模块。<br>
            它们都指向一个对象,该对象的各个成员，分别由模块名和对应的版本要求组成，表示依赖的模块及其版本范围。<br>
        </td>
        </tr>
        <tr>
            <td align="center">
                devDependencies
            </td>
        </tr>
</table>
`dependencies`和`devDependencies`对应的版本可以加上各种限定，主要有以下几种：

<ul>
<li><p><strong>指定版本</strong>：比如<code>1.2.2</code>，遵循“大版本.次要版本.小版本”的格式规定，安装时只安装指定版本。</p>
</li>
<li><p><strong>波浪号（tilde）+指定版本</strong>：比如<code>~1.2.2</code>，表示安装1.2.x的最新版本（不低于1.2.2），但是不安装1.3.x，也就是说安装时不改变大版本号和次要版本号。</p>
</li>
<li><p><strong>插入号（caret）+指定版本</strong>：比如ˆ1.2.2，表示安装1.x.x的最新版本（不低于1.2.2），但是不安装2.x.x，也就是说安装时不改变大版本号。需要注意的是，如果大版本号为0，则插入号的行为与波浪号相同，这是因为此时处于开发阶段，即使是次要版本号变动，也可能带来程序的不兼容。</p>
</li>
<li><p><strong>latest</strong>：安装最新版本。</p>
</li>
</ul>
<h2 id="5-npm项目发布与管理"><a href="#5-npm项目发布与管理" class="headerlink" title="5.npm项目发布与管理"></a><font size=3>5.<code>npm</code>项目发布与管理</font></h2><h3 id="5-1-检查npm源"><a href="#5-1-检查npm源" class="headerlink" title="5.1 检查npm源"></a><font size=3>5.1 检查<code>npm</code>源</font></h3><p>这里为什么需要这一步呢，是因为有的时候自己可能为了让下载速度更快，就把源给换成了<code>taobao</code>，这个源在首次登录的时候可能会有问题，需要处理一下。</p>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">检查npm源</span></span><br><span class="line">npm config get registry</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">配置npm源</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">原始下载源：https://registry.npmjs.org/</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">更换下载源：https://registry.npm.taobao.org</span></span><br><span class="line">npm config set registry https://registry.npm.taobao.org</span><br></pre></td></tr></table></figure>

<h3 id="5-2-本地登录npm"><a href="#5-2-本地登录npm" class="headerlink" title="5.2 本地登录npm"></a><font size=3>5.2 本地登录<code>npm</code></font></h3><p>首次发布项目，需要登陆<code>npm</code>，使用以下命令登录，输入命令之后，填写自己的用户名，密码和注册的邮箱即可，这里要注意淘宝镜像只是提供下载，如果要登陆发布自己的项目， 必须要切换到官方<code>npm</code>源。</p>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">更换npm源为官方源</span></span><br><span class="line">npm config set registry https://registry.npmjs.org/</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">本地登录npm</span></span><br><span class="line">npm login</span><br></pre></td></tr></table></figure>

<p>如果不换回官方<code>npm</code>源的话，登陆的时候就会一直卡死，更换后我出现过因为网络问题导致报错了的，这种的问题不大，出现以下提示说明登陆成功。</p>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Logged in as qidaink on https://registry.npmjs.org/.</span><br></pre></td></tr></table></figure>

<h3 id="5-3-发布项目"><a href="#5-3-发布项目" class="headerlink" title="5.3 发布项目"></a><font size=3>5.3 发布项目</font></h3><p>若项目已经编写完成，那我们就可以发布自己的项目啦，版本发布命令如下。</p>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm publish</span><br></pre></td></tr></table></figure>

<p>出现以下提示内容代表发布成功，之前验证完邮箱，这里还会有发布成功的邮件提醒。</p>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">npm notice </span><br><span class="line">npm notice package: hexo-npm-test@1.0.0</span><br><span class="line">npm notice === Tarball Contents ===</span><br><span class="line">npm notice 288B package.json</span><br><span class="line">npm notice === Tarball Details ===</span><br><span class="line">npm notice name:          hexo-npm-test</span><br><span class="line">npm notice version:       1.0.0</span><br><span class="line">npm notice package size:  285 B</span><br><span class="line">npm notice unpacked size: 288 B</span><br><span class="line">npm notice shasum:        6ec63a53a3c7461ab49dd287e01fa04127cca207</span><br><span class="line">npm notice integrity:     sha512-a46dY8gsp1b2h[...]yf9NfS5tmr7dg==</span><br><span class="line">npm notice total files:   1</span><br><span class="line">npm notice</span><br><span class="line">+ hexo-npm-test@1.0.0</span><br></pre></td></tr></table></figure>

<h3 id="5-4-更新本地项目版本并发布"><a href="#5-4-更新本地项目版本并发布" class="headerlink" title="5.4 更新本地项目版本并发布"></a><font size=3>5.4 更新本地项目版本并发布</font></h3><ul>
<li>手动修改</li>
</ul>
<p>手动修改<code>package.json</code>文件中的版本号。</p>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&quot;version&quot;: &quot;1.0.0&quot;</span><br></pre></td></tr></table></figure>

<ul>
<li>命令修改</li>
</ul>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm version patch</span><br></pre></td></tr></table></figure>

<p>以上命令可以在之前的版本上自动加<code>1</code>，运行完毕后，会出现更新版本的版本号。</p>
<ul>
<li>发布新版本</li>
</ul>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm publish</span><br></pre></td></tr></table></figure>

<p>通过该命令就可以发布新的版本到自己的<code>npm</code>仓库中去，而且之前的版本也存在，也可以通过<code>npm</code>进行安装。</p>
<h3 id="5-5-撤销版本的发布"><a href="#5-5-撤销版本的发布" class="headerlink" title="5.5 撤销版本的发布"></a><font size=3>5.5 撤销版本的发布</font></h3><p>若是我们版本发布错误，我们应该如何撤回已经发布的版本呢？可以通过以下命令进行项目的删除或者某一版本的删除。</p>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm unpublish packageName --force   # 强制撤销,可以删除整个项目</span><br><span class="line">npm unpublish packageName@version   # 可以撤销发布自己发布过的某个版本</span><br></pre></td></tr></table></figure>

<p>如下例子，输入版本撤销命令后，会显示撤销的版本，前边会有一个<code>-</code>，说明撤销成功，此时查看<code>npm</code>会发现，该版本已经消失。不过这样的话，若撤销的版本是新版本，通过命令更新版本的时候，会跳过撤销的版本直接进入下一个版本。</p>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">npm unpublish hexo-npm-test@1.0.1</span> </span><br><span class="line">- hexo-npm-test@1.0.1</span><br></pre></td></tr></table></figure>

<h3 id="5-6-查看版本信息"><a href="#5-6-查看版本信息" class="headerlink" title="5.6 查看版本信息"></a><font size=3>5.6 查看版本信息</font></h3><figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">npm view packageName versions         # 查看历史版本信息(最多只能显示100条)        </span><br><span class="line">npm view packageName versions --json  # 查看所有版本信息</span><br><span class="line">npm view packageName version          # 查看最新版本信息</span><br></pre></td></tr></table></figure>
    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/5d78b485.html">LV01-Hexo-02-npm包的发布与管理</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年07月02日 - 16:16</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/5d78b485.html" title="LV01-Hexo-02-npm包的发布与管理">https://sumumm.github.io/post/5d78b485.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" rel="tag"><i class="fa fa-tag"></i> 博客搭建</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/72cb261c.html" rel="prev" title="LV01-Hexo-03-Hexo的两种插件">
                  <i class="fa fa-angle-left"></i> LV01-Hexo-03-Hexo的两种插件
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/40a23b82.html" rel="next" title="LV01-Hexo-01-Hexo简介与使用">
                  LV01-Hexo-01-Hexo简介与使用 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">false</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
